<?php  include  $this->admin_tpl('header'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/haidaoblue/easyui.css">
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/icon.css">
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/hd_default_config.js"></script>
<div class="content">
	<div class="site">
	<?php echo C('site_name')?> <a href="#">会员财务管理</a> > 提现列表
	</div>
	<span class="line_white"></span>
	<div class="goods mt10">
		<div class="search_ind">
			<input type="hidden" name="m" value="<?php echo GROUP_NAME ?>">
			<input type="hidden" name="c" value="<?php echo MODULE_NAME ?>">
			<input type="hidden" name="a" value="<?php echo ACTION_NAME ?>">
            <span style="margin-right: 10px;">状态</span>
				<select name='status_type' id='group_combbox' class="easyui-combobox" data-options="editable:false,panelHeight:'auto'" style="height: 26px; width:100px;">
                </select>
                <span style="margin-right: 10px;">开始时间 </span>
                <input class="easyui-datebox" name="start" id="start">
                <span style="margin-right: 10px;">至</span>
                <input class="easyui-datebox" name="end" id="end" validType="md['#start']">
			<input id="keyword" class="easyui-textbox" name="keyword" style="width:210px;height: 26px;" prompt="输入会员名称查询">
			<a id="search" href="javascript:;" class="easyui-linkbutton" style="height: 26px;padding-right: 10px;">查询</a>
		</div>
		
		<div class="login mt10" style="border: none;border-right: 1px solid #e6e6e6;">
			<!-- 日志信息 -->
			<dl id="adminwithdraw_log" style="width:100%;"></dl>
			<!-- 财务设置 -->
					</div>
		<div class="clear"></div>
		<?php include $this->admin_tpl('copyright') ?>
	</div>
</div>
<div id="poinospanel" class="easyui-window"  style="width:320px;" closed="true" modal="true" minimizable="false" maximizable="false" collapsible="false" data-options="title:'提现处理'">
		<form id="SetPoinosForm" class="setpoinosform" method="post" action="<?php echo U('doedit'); ?>">
		<div class="login " style="border: none;">
			<div class="table">
				<table>
				<tr style="border-top: none;">
					<td>状态</td>
					<td align="left"><input type="radio" value="1" name="withdraw_status" checked>通过 <input type="radio" value="2" name="withdraw_status">驳回</td>
					<td align="left"></td>
				</tr>
				<tr style="border-top: none;">
					<td>提现手续费</td>
					<td align="left"><input type="text" value="" style="margin:0;" class="text_input1" name="withdraw_fee" ></td>
					<td align="left">元</td>
				</tr>
				<tr style="border-bottom:1px solid #CCCCCC;border-top: none;">
					<td>处理意见</td>
					<td align="left" colspan="2"><input type="text" value="" style="margin:0;" class="input_ss" name="deal_info" ></td>
				</tr>
				</table>
			</div>
		</div>
		<div data-options="region:'south',border:false" style="text-align:right;padding:5px 20px;">
			<a class="easyui-linkbutton box_save"  href="javascript:void(0)" aonclick="$('#SetPoinosForm').submit()" style="padding: 0 10px;">确定</a>
			<a class="easyui-linkbutton"  href="javascript:void(0)" onclick="$('#poinospanel').window('close');" style="padding: 0 10px;">取消</a>
		</div>
			<input type="hidden" name="id" value="" />
		</form>
	</div>
<script type="text/javascript">
$(function(){
	$(".box_save").click(function(){
		var withdraw_status=$("input[name='withdraw_status']:checked").val()
		var withdraw_fee=$("input[name='withdraw_fee']").val()
		var deal_info=$("input[name='deal_info']").val()
		var id=$("input[name='id']").val()
		if(withdraw_fee==""){
			alert("手续费不能为空");	
		}
		if(deal_info==""){
			alert("处理意见不能为空");	
		}
		if(id==""){
			alert("参数错误");	
		}
		$.ajax({
             type: "POST",
             url: "<?php echo U('doedit'); ?>",
             data: {withdraw_status:withdraw_status, withdraw_fee:withdraw_fee,deal_info:deal_info,id:id},
             dataType: "json",
             success: function(data){
				 $('#poinospanel').window('close');
				 if(data.status==1){
                	$(".dostatus"+data.id).parent().html('<font>已提现</font>');
					$(".dostatus2"+data.id).parent().html('<font>已处理</font>');
					$(".deal_info"+data.id).parent().html('<font>'+data.deal_info+'</font>');
				 }
				 if(data.status==2){
                	$(".dostatus"+data.id).parent().html('<font>提现失败</font>');
					$(".deal_info"+data.id).parent().html('<font>'+data.deal_info+'</font>');
				 }
				 alert(data.info);
            }
         });	
	})
	
})
var dom = $('#adminwithdraw_log');
var pageSize = <?php echo PAGE_SIZE?>;
var dataurl = '<?php echo U('index')?>';
var dourl = '<?php echo U('doedit')?>';
var keyword = '<?php echo $keyword?>';
var user_id = '<?php echo $user_id?>';
$(function(){
	dom.datagrid({
		url:dataurl,
		striped:true,
		width:'100%',
		checkOnSelect:false,
		title:"统计概览",  
		fitColumns:true,
		toolbar:[
			{
				id:'exportrows',
				text:'导出',
				iconCls:'icon-export',
			}
		],
		frozenColumns:[[
			{field:'id',checkbox:true}
		]],
		queryParams:{
			keyword:keyword
		},
		scrollbarSize:0,
		pagination:true,
		pageSize:pageSize,
		pageList: [pageSize,pageSize*4,pageSize*8,pageSize*16,pageSize*32,pageSize*64],
		//可以设置每页记录条数的列表
		columns:[[
		{field:'username',title:'会员名',width:'10%',halign:'center',align:'center'},
		{field:'user_type',title:'类型',halign:'center',align:'center',width:'3%',sortable:false,
			formatter:function(value,row,index){
				if(value=="1")return "个人";
				else return "商家";
				}
		}, 
		{field:'withdraw_money',title:'提现金额',width:'7%',halign:'center',align:'center',sortable:true},
		{field:'withdraw_fee',title:'手续费',width:'10%',halign:'center',align:'center',sortable:true},
		{field:'now_money',title:'到账金额',width:'10%',align:'center',sortable:false,
			formatter:function(value,row,index){
				return toDecimal2(row.withdraw_money-row.withdraw_fee);
			}
		},
		{field:'true_name',title:'真实姓名',width:'10%',halign:'center',align:'center',sortable:true},
		{field:'banknum',title:'银行卡号',width:'10%',halign:'center',align:'center',sortable:true},
		{field:'bankaddress',title:'开户地址',width:'10%',halign:'center',align:'center',sortable:true},
		{field:'add_time',title:'时间',width:'10%',align:'center',sortable:false,
			formatter:function(value,row,index){
				return $.fn.datebox.defaults.timeformat(value);
			}
		},
		{field:'withdraw_status',title:'状态',width:'5%',halign:'center',align:'center',sortable:false,
			formatter:function(value,row,index){
			   if(value==0)return "<font class='red dostatus"+row.id+"'>未处理</font>";
			   if(value==1)return "<font>已提现</font>";
			   if(value==2)return "<font>提现失败</font>";
			}
		},
		{field:'userID',title:'操作',width:'5%',align:'center',halign:'center',
			formatter:function(value,row,index){
					var sp_txt="&nbsp;&nbsp;&nbsp;&nbsp;";
					if(row.withdraw_status==0){
					return '<a  href="javascript:void (0)" class="red  dostatus2'+row.id+'" onclick="pay_points('+row.id+','+index+','+row.withdraw_fee+')">处理</a>'}
					else{
					return '<a  href="javascript:void (0)">已处理</a>'	
					}
					
			}
		},
		{field:'deal_info',title:'处理意见',width:'7%',align:'center',halign:'center',
			formatter:function(value,row,index){
				return "<font class='deal_info"+row.id+"'>"+value+"</font>";
			}
		},
		]],onLoadSuccess:function(data){
				$(".panel-title").html(data.title);
				var group = data.status_type;
				group.unshift({"id":"","name":"请选择"})
				$('#group_combbox').combobox({
					data:group,
					valueField:'id',
					textField:'name'
				});
			}
	});
	//回车查询
	$('#keyword').textbox('textbox').bind('keydown',function (e) {
		if (e.keyCode == 13) {
			$('#search').trigger('click');
		}
	});
	$('#exportrows').bind('click', function(){
			var queryParams = dom.datagrid('options').queryParams;
			queryParams.status = $('#group_combbox').combobox('getValue');
			queryParams.start = $('#start').datebox('getValue');
			queryParams.end = $('#end').datebox('getValue');
			queryParams.keyword = $("#keyword").val();
			window.location.href="/index.php?m=user&c=admin_withdraw_log&a=index&act=excel&status="+queryParams.status+"&start="+queryParams.start+"&end="+queryParams.end+"&keyword="+queryParams.keyword;
		});
});
//积分弹窗
function pay_points(value,index,withdraw_fee){
	$('input[name="id"]').val(value);
	$('input[name="withdraw_fee"]').val(withdraw_fee);
	$('#poinospanel').window('open');
}

//增加查询参数，重新加载表格
$('#search').bind('click',function (){
	var queryParams = dom.datagrid('options').queryParams;
		queryParams.status = $('#group_combbox').combobox('getValue');
		queryParams.start = $('#start').datebox('getValue');
		queryParams.end = $('#end').datebox('getValue');
		queryParams.keyword = $("#keyword").val();
		dom.datagrid('options').queryParams = queryParams;
		dom.datagrid('reload');
})
/* tab切换 */
$(function() {
	var tabTitle = ".mt10 dt p a";
	$(tabTitle).click(function(){
		$(this).siblings("a").removeClass("hover").end().addClass("hover");
	});
});
$('#default').addClass('hover');
$('#set_data').hide();
$('.tabs').bind('click',function(){
	if ($(this).attr('data') == 'default') {
		$('.easyui-fluid').show();
		$('#set_data').hide();
	} else {
		$('.easyui-fluid').hide();
		$('#set_data').show();
	}
})
/* 开关切换效果 */
if (<?php echo C('enable') ?> == 0) {
	$('#pays').hide();
	$('#lowest').hide();
}
$('input[name=enable]').bind('change',function(){
	if ($('input[name=enable]:checked').val() == 1) {
		$('#pays').show();
		$('#lowest').show();
	}else{
		$('#pays').hide();
		$('#lowest').hide();
	}
})
/* 保存财务设置 */
$(':submit').click(function(event) {
	var data = new Array();
	data['enable'] = $('input[name=enable]:checked').val();
	data['pays'] = jqchk();
	data['lowest'] = $('input[name=lowest]').val();
	if (data['pays'].length==0 && data['enable'] == 1) {
		alert('请选择充值方式！');
		return false;
	}
	if ($.trim(data['lowest']) == '') {
		alert('请填写最低充值金额');
		return false;
	}
	$(this).submit();
});
//jquery获取复选框值
function jqchk(){
	var chk_value =[];
	$('input[name="pays[]"]:checked').each(function(){
		chk_value.push($(this).val());
	});
	return chk_value;
}
function toDecimal2(x) {    
        var f = parseFloat(x);    
        if (isNaN(f)) {    
            return false;    
        }    
        var f = Math.round(x*100)/100;    
        var s = f.toString();    
        var rs = s.indexOf('.');    
        if (rs < 0) {    
            rs = s.length;    
            s += '.';    
        }    
        while (s.length <= rs + 2) {    
            s += '0';    
        }    
        return s;    
    } 
</script>
